﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace OrderManagement
{
    [Serializable]
    public class OrderDetails
    {
        public List<Goods> goods { get; set; }
        public double Price {
            get
            {
                double a = 0;
                goods.ForEach((m) => a += m.Num * m.Price);
                return a;
            }
        }
       
        public List<Goods> GetGoods()
        {
            return goods;
        }
        public OrderDetails(List<Goods> goods)
        {
            //double price = 0;
            //goods.ForEach((a) => price += a.Num * a.Price);
            this.goods = goods;
            //this.Price = price;
        }
        public OrderDetails() { }
       /* public void Setgoods(List<Goods> goods)
        {
            this.goods = goods;
            double price = 0;
            goods.ForEach((a) => price += a.Num * a.Price);
            this.Price = price;
        }*/

        public override string ToString()
        {
            String str=null;
            goods.ForEach((a) => str += a.ToString()+" ");
            return str;
            
        }
        public override bool Equals(object obj)
        {
            OrderDetails a = obj as OrderDetails;
            return a != null && a.Price == this.Price && this.goods == a.goods;
        }

        public override int GetHashCode()
        {
            int hashCode = 1781122211;
            hashCode = hashCode * -1521134295 + EqualityComparer<List<Goods>>.Default.GetHashCode(goods);
            hashCode = hashCode * -1521134295 + Price.GetHashCode();
            return hashCode;
        }
    }
}
